<?php
require_once('security.php');
  
  if (isset($_POST['submit'])) { // Handle the form

    // Specify the image file
    $imagefile = '../images/' . $_POST['delete'];

    // Check for existence of file
    if (file_exists($imagefile)) {
      unlink($imagefile);
      $response = 'Success. <b>' . $_POST['delete'] . '</b> was deleted.<br />';
    } else {
      $response = 'Sorry, <b>' . $_POST['delete'] . '</b> does not exist. Try another.<br />';
    }
  }

?>

<?php $thisPage = "deleteimage"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Delete an image</title>
<meta name="robots" content="noindex,nofollow" />
<?php require_once('theme/admintheme.php');?>
</head>
<body>

<div id="wrap">



<?php include_once('navigation.php'); ?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Image to be deleted (eg image.jpg)<br />
<input type="text" name="delete" id="delete" size="40" value="<?php if (isset($_POST['submit'])) echo $_POST['delete']; ?>" maxlength="60" />
<br />
<input type="submit" name="submit" value="Delete image" />
</form>

<?php echo $response; ?>

<?php

  echo '<br /><p><b>Current image files:</b></p>';
  $dirname = "../images";
  $dh = opendir($dirname);
  while (false !== ($file = readdir($dh))) {
    if ((strstr($file, '.jpg')) || (strstr($file, '.bmp'))|| (strstr($file, '.jpeg')) || (strstr($file, '.gif')) || (strstr($file, '.png'))) {
      print '<a href="../images/' . $file . '" title="View">' . $file . '</a><br />';
    }
  }
  closedir($dh);

?>

</div>

</body>
</html>
